<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*,java.sql.*,java.text.*, dbAccess.*"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content
-Type" content="text/html; charset=ISO-8859-1" />
<title>Login Process</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
</head>
<body>
<%
	String emailAddress = request.getParameter("txtEmailAddress");
	String password = request.getParameter("txtPassword");
	String type = request.getParameter("cmbLoginType");
	
	Login lgn = new Login();
	int ret = lgn.UserLogin(emailAddress, password, type);
	
	if (ret == -1) //access failed
	{
		//go to home page with error message
		session.setAttribute("errorMsg","Access failed.");
		response.sendRedirect("home.jsp");
	}
	else if (ret == 0) //email address or password problem
	{
		//go to home page with error message
		session.setAttribute("errorMsg","Email address and password do not match.");
		response.sendRedirect("home.jsp");
	}
	else
	{
		//set session attributes
		session.setAttribute("EmailAddress",lgn.getEmailAddress());
		session.setAttribute("SIN",lgn.getSIN());
		session.setAttribute("FirstName",lgn.getFirstName());
		session.setAttribute("LastName",lgn.getLastName());
		session.setAttribute("Name",lgn.fullName()); //vital for logs
		session.setAttribute("Phone", lgn.getPhoneNum());
		session.setAttribute("HomeAddress",lgn.getHomeAddress());
		session.setAttribute("Gender",lgn.getGender());
		session.setAttribute("DateOfBirth",lgn.getDateOfBirth());
		session.setAttribute("Password",lgn.getPassword());
		
		if (type.equals("Doctor"))
		{
			//doctor
			response.sendRedirect("doctorHome.jsp");
		}
		else if (type.equals("Patient"))
		{
			//patient
			response.sendRedirect("patientHome.jsp");
		}
		else if (type.equals("Staff"))
		{
			//staff
			response.sendRedirect("staffHome.jsp");
		}
		else if (type.equals("Financial Officer"))
		{
			//financial
			response.sendRedirect("financeHome.jsp");
		}
		else if (type.equals("Admin"))
		{
			response.sendRedirect("adminHome.jsp");
		}
	}
	
	
%>
</body>
</html>